package com.example.yoho.mvp.presenter;

import com.example.lib_core.mvp.presenter.BasePresenter;
import com.example.yoho.mvp.contract.ShowContract;
import com.example.yoho.mvp.model.entity.ShowEntity;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Observable;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class ShowPresenter extends BasePresenter<ShowContract.Model,ShowContract.View> {
    @Inject
    public ShowPresenter() {
    }
    int page=0;

    public void reuqestShowAll(){
        this.page=page;
        JSONObject shwoJob = new JSONObject();

        try {
            shwoJob.put("page","1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mModel.showModel(shwoJob.toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ShowEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        disposables.add(d);
                        mView.showDialog();
                    }

                    @Override
                    public void onNext(ShowEntity entity) {
                        mView.showView(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.showToast("请求出错"+e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.hideDialog();
                    }
                });
    }
}
